laravel collection filter

41

$collection = collect([1, 2, 3, 4]);

$filtered = $collection->filter(function ($value, $key) {
    return $value > 2;
});

$filtered->all();

// [3, 4]
$itemCollection = collect($contacts);
$filtered = $itemCollection->filter(function($item) use ($search) {
    return stripos($item['username'],$search) !== false;
});
$collection = collect([1,2,3,4]);

$collection->each(function($item){
    return $item*$item;
});

// [1,4,9,16]

Comments

Submit
0 Comments